<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>核酸工作站结果文件上传</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            margin: 50px;
        }
        .container {
            max-width: 600px;
            margin: auto;
            text-align: center;
        }
        input[type="file"] {
            margin: 20px 0;
        }
        #fileList {
            margin: 10px 0;
            color: #555;
        }
        #uploadBtn {
            padding: 10px 20px;
            background-color: #4CAF50;
            color: white;
            border: none;
            cursor: pointer;
        }
        #uploadBtn:hover {
            background-color: #45a049;
        }
    </style>
</head>
<body>
<div class="container">
    <h1>核酸工作站结果文件上传</h1>

    <!-- File Upload Form -->
    <input type="file" id="fileInput" multiple>
    <div id="fileList"></div>
    <button id="uploadBtn">上传</button>

    <div id="status"></div>
</div>
<script charset="utf-8" src="layui/layui.js"></script>
<script>
    // 获取文件输入元素
    const fileInput = document.getElementById('fileInput');
    const fileList = document.getElementById('fileList');
    const uploadBtn = document.getElementById('uploadBtn');
    const status = document.getElementById('status');
/*
    noToken()
    var util = layui.util;

    let terminal = {}

    // 1.获取ip地址  浏览器内核  ip区域  操作系统名称
    var browser = getBrowserInfo().toString();
    terminal.b_kernel = browser;
    localStorage.setItem("b_kernel", browser);
    var systemInfo = ckeckBrowerVersion();

    terminal.os = systemInfo
    terminal.ip_address = localStorage.getItem("ip_address");
    terminal.ip_area = localStorage.getItem("ip_area");


    layui.use(['jquery'], function () {
        var $ = layui.jquery;

        // $.ajaxSetup({
        //     headers: {
        //         'SystemId': 'SYSTEM_LIMS',
        //         'Content-Type': 'application/json',
        //     }
        // });

        $.ajax({
            url: '/openApi/terminal',
            type: 'post',
            headers: {
                'SystemId': 'SYSTEM_LIMS',
                'Content-Type': 'application/json',
            },
            data: JSON.stringify({
                ip_address: '127.0.0.1',
                ip_area: '深圳',
                b_kernel: terminal.b_kernel,
                os: terminal.os
            }),
            dataType: 'json',
            success: function (data) {
                if (data.status == 200) {
                    localStorage.setItem("TerminalInfoKey", data.data);
                }
            }
        });


    });


    layui.use(['jquery'], function () {
        var $ = layui.jquery;

        // $.ajaxSetup({
        //     headers: {
        //         'Authorization': localStorage.getItem("AdminToken"),
        //         'TerminalInfo': localStorage.getItem("TerminalInfoKey"),
        //         'SystemId': 'SYSTEM_LIMS',
        //         'CompanyId': localStorage.getItem("CompanyId"),
        //         'EmployeeId': localStorage.getItem("EmployeeId"),
        //         'Content-Type': 'application/json',
        //     }
        // });

        $.ajax({
            url: '/getBasicInfo',
            type: 'get',
            headers: {
                'Authorization': localStorage.getItem("AdminToken"),
                'TerminalInfo': localStorage.getItem("TerminalInfoKey"),
                'SystemId': 'SYSTEM_LIMS',
                'Content-Type': 'application/json',
                'CompanyId': localStorage.getItem("CompanyId"),
                'EmployeeId': localStorage.getItem("EmployeeId"),
            },
            dataType: 'json',
            success: function (response) {
                if (response.status == 200) {

                    const info = response.data;
                    // info.ygxm
                    layui.$('.user-name').text('欢迎您登录：' + info.ygxm)
                } else if (response.status == 500203) {
                    // layer.msg('登录过期');
                    layer.alert("登录信息已过期", {
                        title: '提示',
                        icon: 1,
                        btn: ['知道了'],
                        yes: function (index) {
                            localStorage.clear()
                            window.location.href = './login.html'
                            layer.close(index)
                        }
                    })

                } else {
                    layer.msg('系统错误，请稍后重试');
                }
            }
        });


    });*/

                        // 监听文件选择事件
    fileInput.addEventListener('change', function () {
        const files = fileInput.files;  // 获取选择的文件列表
        fileList.innerHTML = '';  // 清空之前的文件列表

        // 显示文件名
        for (let i = 0; i < files.length; i++) {
            const listItem = document.createElement('p');
            listItem.textContent = `File: ${files[i].name} (${(files[i].size / 1024).toFixed(2)} KB)`;
            fileList.appendChild(listItem);
        }
    });

    // 监听上传按钮点击事件
    uploadBtn.addEventListener('click', function () {
        if (fileInput.files.length === 0) {
            status.textContent = "请选择要上传的文件！";
            return;
        }

        const formData = new FormData();
        const files = fileInput.files;

        // 将文件添加到 FormData 对象
        for (let i = 0; i < files.length; i++) {
            formData.append('file', files[i]);
        }

        // 使用 fetch API 发送 POST 请求
        fetch('http://192.168.11.3:80/openApi/api/data/nucleicAcidWorkstation/upload', {
            method: 'POST',
            body: formData
        })
            .then(response => {
                if (response.ok) {
                    return response.json();
                } else {
                    throw new Error('上传失败');
                }
            })
            .then(result => {
                status.textContent = '文件上传成功！';
                console.log('Success:', result);
            })
            .catch(error => {
                status.textContent = 'Error uploading file: ' + error.message;
                console.error('Error:', error);
            });
    });
</script>
</body>
</html>
